package com.qyhl.shop.shop.rush.detail;

import com.qyhl.shop.common.ShopUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.shop.ShopRushDetailBean;
import com.qyhl.webtv.commonlib.entity.shop.ShopRushPurchaseTicketBean;

public class ShopRushPurchaseDetailModel implements ShopRushPurchaseDetailContract.ShopRushPurchaseDetailModel {
    private ShopRushPurchaseDetailPresenter mPresenter;

    public ShopRushPurchaseDetailModel(ShopRushPurchaseDetailPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getDetail(int giftId) {
        EasyHttp.post(ShopUrl.SHOP_RUSH_PURCHASE_DETAIL)
                .params("phoneNum", CommonUtils.getInstance().getUserName())
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("giftId", giftId + "")
                .execute(new SimpleCallBack<ShopRushDetailBean>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setError("获取抢购详情失败！");
                    }

                    @Override
                    public void onSuccess(ShopRushDetailBean bean) {
                        mPresenter.setDetail(bean);
                    }
                });
    }


    @Override
    public void doRushPurchase(int giftId, String phoneNum, String sign) {
        EasyHttp.post(ShopUrl.SHOP_RUSH_PURCHASE)
                .params("giftId", giftId + "")
                .params("phoneNum", phoneNum)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("sign", sign)
                .execute(new SimpleCallBack<ShopRushPurchaseTicketBean>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.rushPurchaseError(e.getCode(), e.getMsg());
                    }

                    @Override
                    public void onSuccess(ShopRushPurchaseTicketBean bean) {
                        mPresenter.rushPurchaseResult(bean);
                    }
                });
    }
}
